import akka.actor.*;

public class MyActorA extends UntypedAbstractActor {
//    @Override
//    public Receive createReceive() {
//        return receiveBuilder().match(String.class, result -> {
//            System.out.println("Actor A 接收到消息：" + result);
//            //由 当前 Actor A  发送给 Actor B
//            ActorRef actorref = getContext().actorOf(Props.create(MyActorB.class), "newactorb");
//            actorref.tell("stop",getSelf());
//            //获取原始的Actor 转发给 B
//            //getSender().forward(result,getContext());
//        }).build();
//    }

    public static void main(String[] args) {
        //定义一个Actor管理仓库
        ActorSystem system = ActorSystem.create("sys");
        //将自定义的Actor放入仓库并起个名字
        ActorRef actorDemo = system.actorOf(Props.create(MyActorA.class), "actorDemo");
        //发送消息
        actorDemo.tell("你好",ActorRef.noSender());
    }

    @Override
    public void onReceive(Object message) throws Throwable {
        System.out.println("Actor A 接收到消息：" + message);
        ActorRef actorref = getContext().actorOf(Props.create(MyActorB.class), "newactorb");
        actorref.tell("stop",getSelf());
    }
}
